package algorithm.unionfind;

/**
 * @Description:
 * @Author Ammar
 * @Create 2023/5/18 07:51
 */
public class QuickUnion_rank_spliting extends QuickUnion_rank {
    public QuickUnion_rank_spliting(int capacity) {
        super(capacity);
    }

    @Override
    public int find(int v) {
        rangeCheck(v);
        while (v != parents[v]) { // v = 1, parents[v] = 2
            int p = parents[v];
            // v.parent = v.parent.parent
            parents[v] = parents[parents[v]];
            v = p;
        }
        return v;
    }
}
